package com.frank.utils;

import java.util.ArrayList;

/**
 * @Description 双向链表
 * @Author zhoujr
 * @Data 2024/11/23 14:45
 */
public class DoublyListNode {
    public int val;
    public DoublyListNode pre;
    public DoublyListNode next;

    DoublyListNode() {
    }

    DoublyListNode(int val) {
        this.val = val;
    }

    DoublyListNode(int val, DoublyListNode pre, DoublyListNode next) {
        this.val = val;
        this.pre = pre;
        this.next = next;
    }

    public static DoublyListNode toListNode(ArrayList<Integer> list) {
        DoublyListNode last = null;
        DoublyListNode temp = null;
        for (int i = list.size() - 1; i >= 0; i--) {
            int num = list.get(i);
            last = new DoublyListNode(num, null, last);
            if (temp != null) {
                temp.pre = last;
            }
            temp = last;
        }
        return last;
    }

}
